﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace BHair.Base
{
    public partial class frmhyfladd : Form
    {
        public frmhyfladd()
        {
            InitializeComponent();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        private void button1_Click(object sender, EventArgs e)
        {
            if (chuanzhi.ifup != 1)
            {
                try
                {
                    int chuzhi = 0;
                    if (checkBox1.Checked == true)
                    {
                        chuzhi = 1;
                    }
                    else
                    {
                        chuzhi = 0;
                    }
                    int jc = 0;
                    if (checkBox2.Checked == true)
                    {
                        jc = 1;
                    }
                    else
                    {
                        jc = 0;
                    }
                    SqlConnection conn = new SqlConnection(constr);
                    conn.Open();
                    string sql = string.Format("INSERT INTO [card]([cname],[cdiscount] ,[cmoney],[积分方式] ,[优惠方式] ,[储值] ,[计次],[积分率]) VALUES ('{0}' ,'{1}' ,'{2}','{3}','{4}',{5},{6},{7})", textBox1.Text, textBox2.Text,textBox3.Text,comboBox2.Text,comboBox1.Text,chuzhi,jc,textBox4.Text);
                    SqlCommand comm = new SqlCommand(sql, conn);
                    comm.ExecuteNonQuery();
                    MessageBox.Show("添加成功！");
                    this.Close();
                    conn.Close();
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message);
                }
            }
            else
            {
                try
                {
                    int cz = 0;
                    if (checkBox1.Checked == true)
                    {
                        cz = 1;
                    }
                    else
                    {
                        cz = 0;
                    }
                    int jc = 0;
                    if (checkBox2.Checked == true)
                    {
                        jc = 1;
                    }
                    else
                    {
                        jc = 0;
                    }
                    SqlConnection conn = new SqlConnection(constr);
                    conn.Open();
                    string sql = string.Format("UPDATE [card] SET [cname] = '{0}' ,[cdiscount] = {1},[cmoney]='{2}',积分率={3},积分方式='{4}',优惠方式='{5}',储值={6},计次={7} WHERE  cid={8}", textBox1.Text, textBox2.Text, textBox3.Text,textBox4.Text,comboBox2.Text,comboBox1.Text,cz,jc,chuanzhi.hyfl);
                    SqlCommand comm = new SqlCommand(sql, conn);
                    comm.ExecuteNonQuery();
                    conn.Close();
                    this.Close();
                }
                catch (Exception ea)
                {
                    MessageBox.Show(ea.Message);
                }

            }
        }

        private void frmhyfladd_Load(object sender, EventArgs e)
        {
           
            if (chuanzhi.ifup == 1)
            {
                this.Text = "卡分类修改";
                textBox1.Text = chuanzhi.hyflname;
                textBox2.Text = chuanzhi.hyzl;
                textBox3.Text = chuanzhi.bankajine;
                comboBox1.Text = chuanzhi.yhfs.Trim();
                comboBox2.Text = chuanzhi.jffs.Trim();
                if (chuanzhi.ifcz == 1)
                {
                    checkBox1.Checked = true;
                }
                else
                {
                    checkBox1.Checked = false;
                }

                if (chuanzhi.ifjc == 1)
                {
                    checkBox2.Checked = true;
                }
                else
                {
                    checkBox2.Checked = false;
                }
                textBox4.Text = chuanzhi.jfl.ToString();

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
